<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/3/15
 * Time: 16:03
 */

echo "<title>9-3 类的属性 </title>";
echo "<p style='text-align: center'><a href=\"index.php\"><font size=\"4\">目录</font></a></p>";
header("Content-type: text/html; charset=utf-8");
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";

class Car{
    //在这里定义一个共有属性name
    public $name = '汽车';

    //定义受保护的属性
    protected $corlor = '白色';

    //定义私有属性
    private $price = '1000000';

    public function getPrice(){
        return $this->price; //内部访问私有属性
    }
}

$car = new Car();
//在这里输出$car对象的name属性
echo $car->name; //调用对象的name属性
echo $car->corlor; //错误 受保护的属性不允许外部调用
echo $car->price; //错误 私有属性不允许外部调用


